from rest_framework import serializers

from .models import *


class RoleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Role
        fields = ('role',)


class InstructorSerializer(serializers.ModelSerializer):
    class Meta:
        model = Instructor
        fields = ('instructor',)


class StudentClassSerializer(serializers.ModelSerializer):
    instructor_name = InstructorSerializer()

    class Meta:
        model = StudentClass
        fields = ('classname', 'instructor_name')


class UserInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserInfo
        fields = ('id', 'role_id', 'instructor_id', 'sex', 'student_class', 'id_card', 'bank_card')
        depth = 1  # depth表示：找到嵌套关系的第一层


class UserSerializer(serializers.ModelSerializer):
    userinfo = UserInfoSerializer(many=True)

    class Meta:
        model = User
        fields = ('id', 'name', 'userinfo')
